#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

#define PORT    8000

int main(int argc, char * argv[]) {
    int connfd;
    struct sockaddr_in addr_in;
    char buffer[1024] = {0};

    connfd = socket(AF_INET, SOCK_STREAM, 0);
    if (connfd == -1) {
        perror("socket failed");
        return EXIT_FAILURE;
    }

    addr_in.sin_family = AF_INET;
    addr_in.sin_port = htons(PORT);
    inet_pton(AF_INET, "127.0.0.1", &addr_in.sin_addr);

    if (connect(connfd, (struct sockaddr *)&addr_in,
                sizeof(addr_in)) == -1) {
        perror("connect failed");
        return EXIT_FAILURE;
    }

    char * message = "hello from client";
    send(connfd, message, strlen(message), 0);
    printf("[SEND]: %s\n", message);
    read(connfd, buffer, 1024);
    printf("[RECV]: %s\n", buffer);

    return 0;
}
